package com.chpro.http.yixin.servlet;
import org.apache.commons.configuration.PropertiesConfiguration;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * 配置文件类
 * Created by Administrator on 14-10-2.
 */
public class ExtendActionServlet {
    private static final String COMMON_CONFIG_FILE = "common.properties";
    private static final String TO_KEN_FILE = "yixin/toKen.properties";  //易信toKen配置文件

    public static PropertiesConfiguration commonConfig = null;

    /**
     * 加载配置文件
     * @throws Exception
     */
    public void init() throws Exception{
        commonConfig = new PropertiesConfiguration();
        ClassLoader c1 = this.getClass().getClassLoader();
        URL url=c1.getResource(COMMON_CONFIG_FILE);
        InputStream cfgIs=url.openStream();
        commonConfig.load(cfgIs);
    }

    /**
     * 获取易信配置文件toKen
     * @param key
     * @return
     * @throws Exception
     */
    public static String getYixinToKen(String key)throws Exception{
        PropertiesConfiguration toKenConfig = new PropertiesConfiguration();
        ClassLoader c1 = ExtendActionServlet.class.getClassLoader();
        URL url=c1.getResource(TO_KEN_FILE);
        InputStream cfgIs=url.openStream();
        toKenConfig.load(cfgIs);
        return toKenConfig.getString(key);
    }

    public static void main(String[] args)throws Exception{
        String str = ExtendActionServlet.getYixinToKen("access_token");
        System.out.println(str);
    }
}
